#!/bin/bash
clear

RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PLAIN="\033[0m"

if [ "${EUID}" -ne 0 ]; then
    echo -e "${RED}You need to run this script as root!${PLAIN}" && exit 1
fi

echo "================ [ SSHD & OVPN: CLIENT LISTS ]"
echo "Username      | Expire date"
echo "----------------------------------------------"
while read file; do
    getClients="$(echo $file | cut -d ":" -f 1)"
    expireDate="$(chage -l $getClients | grep "Account expires" | awk -F": " '{print $2}')"
    getUid="$(echo $file | grep -v nobody | cut -d ":" -f 3)"
    if [[ $getUid -ge 1000 ]]; then
        printf "%-15s %2s\n" "$getClients" "$expireDate"
    fi
done < /etc/passwd
totalClient="$(awk -F ":" '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd | wc -l)"

echo "----------------------------------------------"
echo -e "${YELLOW}Total:${PLAIN} ${GREEN}$totalClient${PLAIN} users"
echo "----------------------------------------------"
echo "Copyright 2021 Cybertize, Allright Reserved."
echo "=============================================="
echo "";
